1 00:00:00,380 --> 00:00:01,400 Welcome back. 2 00:00:01,400 --> 00:00:04,790 We're now going to start scripting our local script for our GUI. 3 00:00:04,820 --> 00:00:09,200 We need a script, all the functionality for our command line frame and the message frame that will 4 00:00:09,200 --> 00:00:10,610 appear on our screen. 5 00:00:10,610 --> 00:00:15,800 So if we take our admin GUI and put it inside of starter GUI so we can go ahead and take a look at it, 6 00:00:15,800 --> 00:00:19,010 we're going to have the main frame that's going to act as our command line. 7 00:00:19,010 --> 00:00:21,830 So let me move it up so it's visible on the screen. 8 00:00:21,830 --> 00:00:25,340 So we'll set it to a position like 0.55. 9 00:00:25,340 --> 00:00:27,890 This will be our command line where we can enter in our commands. 10 00:00:27,890 --> 00:00:32,570 And we can see all of the commands listed out here that matches whatever we're typing inside of this 11 00:00:32,570 --> 00:00:33,380 box. 12 00:00:33,380 --> 00:00:38,030 And then we're also going to have a message frame to display any messages to the player when they, 13 00:00:38,030 --> 00:00:42,410 you know, might fill out a command wrong or something happens during the command. 14 00:00:42,410 --> 00:00:45,740 And we'll tween that to about the center of the screen. 15 00:00:46,380 --> 00:00:49,140 So to get started, we're going to need a few services. 16 00:00:49,140 --> 00:00:51,900 Of course we're going to need replicated storage. 17 00:00:54,630 --> 00:00:57,780 We're going to need the player service. 18 00:00:59,880 --> 00:01:03,990 We're also going to need the tween service to tween UI elements. 19 00:01:06,240 --> 00:01:12,420 And then we're also going to need a service called the Context Action Service. 20 00:01:14,570 --> 00:01:21,530 And the purpose of this service is for us to be able to listen for specific inputs on the client based 21 00:01:21,530 --> 00:01:23,150 on different contexts. 22 00:01:23,150 --> 00:01:29,180 So instead of having to use the user input service, which runs all of the time, we can instead use 23 00:01:29,180 --> 00:01:34,670 a context and bind a specific function to listen for when a key is pressed. 24 00:01:34,670 --> 00:01:39,650 And we can connect and disconnect that context action whenever we want in our script. 25 00:01:39,650 --> 00:01:43,580 So it's actually a little bit better than having to use the user input service. 26 00:01:43,580 --> 00:01:50,840 The service also allows us to only listen to those inputs when they are not observed by the game engine. 27 00:01:50,840 --> 00:01:56,570 So for example, if we're listening for when a player presses the colon key on their keyboard, but 28 00:01:56,570 --> 00:02:00,920 we only want to bring up the UI when you know they're they're doing nothing else on their screen. 29 00:02:00,920 --> 00:02:05,630 So if they're typing in chat up here, we of course don't want to pop up this command line. 30 00:02:05,630 --> 00:02:11,180 Well, the context, uh, the context action service automatically handles that for us. 31 00:02:11,180 --> 00:02:15,590 Now, some variables we're going to need of course, is the admin assets folder. 32 00:02:15,590 --> 00:02:17,510 So that's going to be in replicated storage. 33 00:02:17,510 --> 00:02:20,240 And we're going to wait for that folder to replicate. 34 00:02:20,600 --> 00:02:23,300 And then inside of that folder we're going to need the two events. 35 00:02:23,300 --> 00:02:25,820 One is going to be that request remote function. 36 00:02:27,940 --> 00:02:31,660 And then we're also going to need that communication remote event. 37 00:02:35,150 --> 00:02:37,580 We're going to have a reference to the local player here. 38 00:02:37,580 --> 00:02:39,710 So players dot local player. 39 00:02:40,860 --> 00:02:47,670 We're going to want to require that module script in admin assets, which is all of our commands. 40 00:02:49,920 --> 00:02:53,580 And then we also want to have access to the admin settings module script. 41 00:02:59,490 --> 00:03:04,260 And then the next thing we need to do here is to make some references for the things inside of our guy. 42 00:03:04,290 --> 00:03:07,680 So we want to reference the guy itself, which is just script dot parent. 43 00:03:08,160 --> 00:03:11,850 We want to have a reference to the main frame or the command line. 44 00:03:11,850 --> 00:03:14,010 We'll just call it main frame guy. 45 00:03:14,040 --> 00:03:15,450 Wait for child main. 46 00:03:16,780 --> 00:03:21,160 And then we could do the same thing for the scrolling frame that is inside of our main frame. 47 00:03:21,160 --> 00:03:24,910 So we have a scrolling frame in here that we're going to fill up with commands. 48 00:03:24,910 --> 00:03:26,800 And I've made these example commands here. 49 00:03:26,800 --> 00:03:30,580 So we're just going to duplicate these and put them inside of our scrolling frame. 50 00:03:30,580 --> 00:03:35,920 And they're going to display stuff like all the commands that match you know whatever. 51 00:03:35,920 --> 00:03:39,040 So we'll have a command in here like this. 52 00:03:39,040 --> 00:03:44,350 And it'll show up and it'll display to us all the commands that match whatever we're typing in here. 53 00:03:44,770 --> 00:03:47,890 So main frame, wait for child scrolling frame. 54 00:03:48,880 --> 00:03:52,090 We'll want to have a reference to that message frame as well. 55 00:03:54,480 --> 00:03:58,110 We want to have a reference to our input box inside of our mainframe. 56 00:03:58,110 --> 00:04:01,830 So mainframe Way.for child text box. 57 00:04:03,160 --> 00:04:05,260 Only rename this to Input Box. 58 00:04:06,020 --> 00:04:10,880 And then I want to have a reference to that example command here, so we can clone it and put it inside 59 00:04:10,880 --> 00:04:14,360 of our scrolling frame for all the commands that match whatever we're typing. 60 00:04:14,360 --> 00:04:16,970 So example command is equal to main frame. 61 00:04:16,970 --> 00:04:19,190 Wait for child example command. 62 00:04:20,660 --> 00:04:24,740 And then another thing I want to be able to store in this script is our rank. 63 00:04:24,740 --> 00:04:27,020 So I'm going to call it my rank level. 64 00:04:27,020 --> 00:04:29,150 And we're going to use our request event. 65 00:04:29,150 --> 00:04:33,140 And we're going to invoke to the server to get our rank. 66 00:04:33,140 --> 00:04:37,580 So we're asking the server, hey, return to us what our rank is inside of this script. 67 00:04:38,200 --> 00:04:42,280 And that actually means we're going to have to go back to our admin handler. 68 00:04:42,700 --> 00:04:46,690 So inside of our on server invoke function. 69 00:04:47,050 --> 00:04:55,240 Um, the problem here is we should actually check this section right here inside of this context only 70 00:04:55,240 --> 00:04:59,500 because we're requesting to get a rank and we're not passing a table here. 71 00:04:59,500 --> 00:05:03,220 But since this if statement is here, it's going to check whether or not we pass a table. 72 00:05:03,220 --> 00:05:06,160 And if we don't it's going to return false, which we don't want to happen. 73 00:05:06,160 --> 00:05:11,620 We only want to check to see if there's a table here for specific contexts that require for us to pass 74 00:05:11,620 --> 00:05:14,050 a table, like for executing a command. 75 00:05:14,050 --> 00:05:15,700 So we're going to get rid of that here. 76 00:05:15,700 --> 00:05:19,570 And instead we've placed it inside of this section of the if statement. 77 00:05:19,570 --> 00:05:24,100 Otherwise we can get our rank and it's going to return to us the number that represents our rank. 78 00:05:24,100 --> 00:05:28,750 Now let's go ahead and define some constants for our guy. 79 00:05:28,900 --> 00:05:34,060 Some of the constants are going to be the different positions that our frames are going to be in when 80 00:05:34,060 --> 00:05:36,370 they're visible and not visible on the screen. 81 00:05:36,370 --> 00:05:42,100 So for our main frame, when it's visible on the screen, we're going to have it at a Y position of 82 00:05:42,100 --> 00:05:43,840 0.55 scale. 83 00:05:43,840 --> 00:05:47,380 And when it's not visible, it's going to be at a scale of one. 84 00:05:47,380 --> 00:05:51,730 And then for the message frame, we're going to have it visible at 0.5 scale. 85 00:05:51,730 --> 00:05:54,790 And when it's not visible, we'll just put it at something like -0.3. 86 00:05:54,790 --> 00:05:57,040 So we don't see it on the screen anymore. 87 00:05:57,280 --> 00:05:59,260 So let's go ahead and hard code those here. 88 00:05:59,260 --> 00:06:01,900 We're going to have one called message frame. 89 00:06:01,900 --> 00:06:08,770 And we'll call it visible equal to a new Udim 0.5 scale on the x axis. 90 00:06:08,770 --> 00:06:11,380 Nothing on the x offset. 91 00:06:11,380 --> 00:06:15,340 And then 0.5 on the y scale and nothing on the y offset. 92 00:06:16,000 --> 00:06:20,230 And then we could do the same thing for when it is invisible or not visible. 93 00:06:23,090 --> 00:06:25,760 And that was -0.3 and then zero. 94 00:06:25,970 --> 00:06:28,490 And then we could do the same thing for our main frame. 95 00:06:28,490 --> 00:06:32,030 So main frame visible is equal to a new dim two. 96 00:06:32,120 --> 00:06:38,600 That's going to be 0.950 and then 0.55 for it to be visible. 97 00:06:38,600 --> 00:06:41,000 And then when it's not visible. 98 00:06:43,770 --> 00:06:48,630 Oops is a ball Utum 2.92.950. 99 00:06:48,630 --> 00:06:51,420 And then it's, uh, one and then zero. 100 00:06:52,740 --> 00:06:57,030 And then some other text will have in here I'm going to use. 101 00:06:57,880 --> 00:07:05,080 Uh, we'll call this one Success Text, and we're going to set it to executed successfully. 102 00:07:08,630 --> 00:07:16,010 Because what the plan is here is that when we have our main frame on the screen, when we type in a 103 00:07:16,010 --> 00:07:20,630 command and hit enter, I want to replace this text that you see here in this text box. 104 00:07:20,630 --> 00:07:28,370 So if I go to my text box and we scroll down to our placeholder text, I want to replace it with successfully 105 00:07:28,610 --> 00:07:34,460 executed command to let them know that they, you know, successfully executed the command on their 106 00:07:34,460 --> 00:07:35,000 end. 107 00:07:35,600 --> 00:07:39,620 And then we can set it back to the default text of enter command here. 108 00:07:40,190 --> 00:07:42,290 So we'll create another constant for that as well. 109 00:07:42,290 --> 00:07:44,900 We'll call it uh original text. 110 00:07:44,900 --> 00:07:48,740 And that's going to be equal to uh enter command here. 111 00:07:49,320 --> 00:07:55,950 And then let me put this back to be invisible on the screen again at the Y scale of one. 112 00:07:56,130 --> 00:07:58,860 Next up, we're going to need quite a few functions here. 113 00:07:58,860 --> 00:08:01,020 Inside of our GUI. 114 00:08:01,020 --> 00:08:06,960 One's going to be for getting all of the commands that we are authorized to use. 115 00:08:06,960 --> 00:08:12,270 I'm going to call it Get Authorized authorized commands. 116 00:08:12,540 --> 00:08:17,640 And it's just going to return to us a table of all the commands that we're authorized to use based on 117 00:08:17,640 --> 00:08:18,780 our rank level. 118 00:08:19,230 --> 00:08:24,450 We're going to have a function, I'm going to call it create command label. 119 00:08:24,450 --> 00:08:30,150 And this is going to be for duplicating our example command text label and putting some text in it. 120 00:08:30,150 --> 00:08:34,230 So we'll pass uh, some text to this function which will be a string. 121 00:08:34,230 --> 00:08:37,590 And then we can set up, you know, our command label. 122 00:08:38,640 --> 00:08:44,880 We'll have a function for clearing out all of the different text labels within our scrolling frame. 123 00:08:44,880 --> 00:08:48,840 So I can call this function clear scrolling frame. 124 00:08:50,170 --> 00:08:54,040 And then we're also going to have a function to update the scrolling frame. 125 00:08:54,040 --> 00:08:57,670 I'm going to call it update scrolling frame. 126 00:08:58,630 --> 00:09:05,170 And the purpose of this is to insert all of the different commands that match whatever we're typing 127 00:09:05,170 --> 00:09:08,710 in the scrolling frame or inside of our text box. 128 00:09:08,710 --> 00:09:14,710 So whenever we're typing stuff into our text box, we want to continually update whatever's going to 129 00:09:14,710 --> 00:09:19,570 be inside of our scrolling frame to match whatever we're typing in the text box, right? 130 00:09:20,600 --> 00:09:27,140 And the plan here for this function is that we're going to pass a table of all of the commands that 131 00:09:27,140 --> 00:09:29,750 currently match whatever they're typing in the text box. 132 00:09:29,750 --> 00:09:32,240 So we can call this table matching commands. 133 00:09:32,660 --> 00:09:37,490 Now that means we're going to need a function to actually handle when the text gets changed within our 134 00:09:37,490 --> 00:09:38,300 text box. 135 00:09:38,300 --> 00:09:41,090 So we can call this function on text changed. 136 00:09:41,090 --> 00:09:46,820 And in here we can do all the functionality for searching up all of the different commands that match, 137 00:09:46,820 --> 00:09:50,120 and update our scrolling frame with those matching commands. 138 00:09:50,480 --> 00:09:56,480 Another function we're going to need is to display a message on our screen using our message frame, 139 00:09:56,480 --> 00:10:01,070 and that takes again, more text to put in our display message. 140 00:10:01,070 --> 00:10:08,090 And then another function we're going to need is to listen for when that button inside of our message 141 00:10:08,090 --> 00:10:08,990 label gets pressed. 142 00:10:08,990 --> 00:10:12,470 So we'll call it on message frame button clicked. 143 00:10:13,910 --> 00:10:16,520 Alrighty, now some events we're going to need to listen to. 144 00:10:16,550 --> 00:10:23,180 First off, uh, with our input box, we want to listen for when a player hits enter and inputs text, 145 00:10:23,180 --> 00:10:26,960 and we have to listen to an event called Focused Lost. 146 00:10:27,320 --> 00:10:29,360 We're going to connect a function to this. 147 00:10:29,360 --> 00:10:35,330 And this event passes to us a variable or a boolean that tells us whether or not the player pressed 148 00:10:35,330 --> 00:10:38,120 enter when they lost focus of the text box. 149 00:10:38,120 --> 00:10:40,370 So we can call this enter pressed. 150 00:10:41,240 --> 00:10:45,500 And in here we can check whether or not they pressed enter, and if they did, we can go and try and 151 00:10:45,500 --> 00:10:46,940 execute a command. 152 00:10:47,180 --> 00:10:50,090 The next thing we want to listen to is when the input box. 153 00:10:50,090 --> 00:10:53,900 And we're going to use the get property change signal going to get the text. 154 00:10:53,900 --> 00:10:57,830 When this changes we're going to connect our on text change function. 155 00:10:59,070 --> 00:11:06,180 And then for our message frame, we're going to wait for our text button that's inside of there, which 156 00:11:06,180 --> 00:11:08,430 is that okay button you saw earlier. 157 00:11:08,430 --> 00:11:13,950 And whenever that gets clicked by our mouse again we're going to connect our on message frame button. 158 00:11:13,950 --> 00:11:15,000 Clicked function. 159 00:11:15,520 --> 00:11:19,750 And then here we're going to use the Context action service. 160 00:11:19,750 --> 00:11:23,230 And we're going to use a function in there called bind action. 161 00:11:23,620 --> 00:11:26,110 So we can name this action whatever we would like. 162 00:11:26,140 --> 00:11:30,820 I'm going to call this action uh tween command line. 163 00:11:31,090 --> 00:11:36,070 And the function for this is going to tween the command line onto our screen. 164 00:11:36,100 --> 00:11:38,830 Of course, there's a couple more things we need to pass to this function. 165 00:11:38,830 --> 00:11:42,490 There is a boolean we have to pass called Create touch button. 166 00:11:42,490 --> 00:11:44,500 And this is for mobile devices. 167 00:11:44,500 --> 00:11:49,300 So whether or not it'll show a button on the screen of mobile devices. 168 00:11:49,330 --> 00:11:51,130 Uh currently we don't care about mobile devices. 169 00:11:51,130 --> 00:11:52,720 So I'm going to set this to false. 170 00:11:52,720 --> 00:11:58,360 And then the last thing we need to pass here is the enum Keycode or enum user input type that represents 171 00:11:58,360 --> 00:12:00,040 the input we need to bind. 172 00:12:00,040 --> 00:12:06,580 So for this particular one we want to bind to the enum dot Keycode dot semicolon. 173 00:12:06,580 --> 00:12:13,360 So whenever a player presses the semicolon and the internal game engine did not observe the input or 174 00:12:13,360 --> 00:12:19,360 aka, they didn't use chat or anything else, then we're going to execute this lambda function in here. 175 00:12:19,360 --> 00:12:22,420 The last event we need to listen to is our comms event. 176 00:12:22,420 --> 00:12:26,140 So on client event we're going to connect a function to this. 177 00:12:26,140 --> 00:12:30,490 And again we're going to get passed an action and any arguments to go with that action. 178 00:12:30,760 --> 00:12:35,710 And if you remember inside of our admin handler when we use the fire client function, we want to tell 179 00:12:35,710 --> 00:12:41,770 the player to display a message containing a table with the text of the message. 180 00:12:41,770 --> 00:12:49,900 So we could put an if statement here of if action is equal to display message, then we can use our 181 00:12:49,900 --> 00:12:52,780 display message function and pass args one. 182 00:12:53,740 --> 00:12:56,770 And that means args one is a string. 183 00:12:58,880 --> 00:13:01,760 So let's go ahead and start filling out these functions up here. 184 00:13:02,270 --> 00:13:07,370 So it should be pretty easy for us to figure out what commands were authorized to use, because we're 185 00:13:07,370 --> 00:13:09,860 storing our rank level here in this variable. 186 00:13:09,860 --> 00:13:12,800 So I'm going to create a table called allowed. 187 00:13:13,730 --> 00:13:20,240 And we're going to loop through every single command in pairs commands dot current commands. 188 00:13:20,240 --> 00:13:23,780 So we're going into our commands module script. 189 00:13:23,780 --> 00:13:26,870 And we're going to loop through every single command that exists in here. 190 00:13:26,870 --> 00:13:30,950 And we're going to check to see if we have permission to use the command. 191 00:13:30,950 --> 00:13:33,770 So if command dot minimum rank. 192 00:13:33,770 --> 00:13:35,390 Minimum rank. 193 00:13:36,270 --> 00:13:41,760 If it is greater than my rank level, then we're just going to continue looping because we don't have 194 00:13:41,760 --> 00:13:43,290 access to this command. 195 00:13:43,320 --> 00:13:49,770 However, if the rank is equal to or less than our rank, then we can insert this into our allow table. 196 00:13:49,770 --> 00:13:52,110 So we'll insert this command into our table. 197 00:13:52,110 --> 00:13:56,070 And then once we're done looping through all the commands, we can just return this allowed table at 198 00:13:56,070 --> 00:13:56,700 the end. 199 00:13:56,820 --> 00:14:01,830 And actually what I'll do right here is I'll create a variable, I'm going to call it Authorize commands. 200 00:14:01,830 --> 00:14:07,110 And we're going to use our Get Authorized commands function to, you know, store all the commands we're 201 00:14:07,110 --> 00:14:07,950 authorized to use. 202 00:14:07,950 --> 00:14:09,870 And we're going to use this in a bit. 203 00:14:09,870 --> 00:14:13,020 The next thing we want to fill out is creating a command label. 204 00:14:13,020 --> 00:14:15,930 So this should be pretty easy as well. 205 00:14:15,930 --> 00:14:20,310 All we need to do is create a clone of our command label or example command. 206 00:14:20,310 --> 00:14:22,530 So example command we're going to clone it. 207 00:14:22,800 --> 00:14:27,870 We're going to set the text inside of it equal to the text that is passed to this function. 208 00:14:27,870 --> 00:14:32,040 And then we're going to set the parent equal to the scrolling frame. 209 00:14:32,880 --> 00:14:36,840 And then you could also set the clone dot visibility to true. 210 00:14:38,080 --> 00:14:40,840 Now to clear our scrolling frame again, this should be pretty simple. 211 00:14:40,840 --> 00:14:46,960 We're going to loop through every single child of the scrolling frame, so we can do for every element 212 00:14:46,960 --> 00:14:49,270 in Ipairs scrolling frame. 213 00:14:49,270 --> 00:14:50,590 Get children. 214 00:14:51,550 --> 00:14:57,730 What we'll do is we'll make sure that it is a text label, because inside of our scrolling frame is 215 00:14:57,730 --> 00:15:00,910 a UI list layout, and we do not want to destroy this. 216 00:15:00,910 --> 00:15:09,640 So if not element is a text label, then we're just going to continue looping. 217 00:15:09,850 --> 00:15:12,460 Otherwise we can go ahead and destroy this element. 218 00:15:13,890 --> 00:15:15,690 Pretty simple for that function. 219 00:15:15,720 --> 00:15:19,470 The next function I want to do here is to update our scrolling frame. 220 00:15:19,470 --> 00:15:25,500 So before we start inserting new commands inside of our scrolling frame, we need to first clear out 221 00:15:25,500 --> 00:15:29,010 any other text label that was previously within our scrolling frame. 222 00:15:29,520 --> 00:15:36,150 And then once we do that, we can loop through every single command in the matching commands parameter. 223 00:15:36,810 --> 00:15:42,480 And what we could do with each one of these commands is we could create a clone of the example command 224 00:15:42,480 --> 00:15:47,220 label, and then we can create a variable for the text we want to insert in there. 225 00:15:47,220 --> 00:15:50,610 So we could first do admin settings. 226 00:15:50,610 --> 00:15:52,530 We want to get the prefix. 227 00:15:52,530 --> 00:15:56,910 And then we want to concatenate it with the commands dot usage. 228 00:15:56,910 --> 00:16:01,470 And for this one we could just get the first usage that exists for the command. 229 00:16:01,470 --> 00:16:08,400 So if our command was like set speed then the usage would appear as set speed in the string. 230 00:16:09,380 --> 00:16:14,450 And then what we would do next is we would loop through every single parameter. 231 00:16:14,450 --> 00:16:20,000 So every single parameter in ipairs command dot parameters. 232 00:16:21,390 --> 00:16:24,840 We want to concatenate it to our text string. 233 00:16:24,840 --> 00:16:30,390 So we could do text and concatenate it with, uh, inside of brackets. 234 00:16:30,390 --> 00:16:37,290 We're going to put the type of this parameter and we're going to format it with the parameter type. 235 00:16:37,410 --> 00:16:44,640 So if we have a command like set speed and we require first to pass a player and then a number, this 236 00:16:44,640 --> 00:16:47,970 is what it's going to look like inside of our command line. 237 00:16:47,970 --> 00:16:51,360 It's going to tell us okay you need to type out the command like this. 238 00:16:51,360 --> 00:16:53,640 The first parameter is a player. 239 00:16:53,640 --> 00:16:55,590 And then the second one is a number. 240 00:16:55,590 --> 00:17:00,600 And then once we do that, all we need to do is call our create command label function and pass the 241 00:17:00,600 --> 00:17:02,370 text we just created to it. 242 00:17:02,370 --> 00:17:02,820 All right. 243 00:17:02,820 --> 00:17:06,480 So the next function we need to fill out is our on text change function. 244 00:17:07,070 --> 00:17:12,980 So we're going to have to get the text that is inside of our text box. 245 00:17:12,980 --> 00:17:14,480 So I'm going to create a variable. 246 00:17:14,480 --> 00:17:17,030 I'll just call it uh search text. 247 00:17:17,030 --> 00:17:23,390 And it's going to be a table containing all of the different string elements that we've typed out inside 248 00:17:23,390 --> 00:17:24,170 of the text box. 249 00:17:24,170 --> 00:17:26,600 So again we're going to use the string dot split command. 250 00:17:26,600 --> 00:17:33,260 And we're going to split up all of the text that is inside of our input box by a space. 251 00:17:33,900 --> 00:17:37,830 And we're actually going to make this lowercase again to stay consistent. 252 00:17:38,340 --> 00:17:45,450 And then what we could do here is we could see if the search text and see if the very first element 253 00:17:45,450 --> 00:17:48,090 in there is an empty table. 254 00:17:48,090 --> 00:17:50,910 So let's say they didn't put anything at all. 255 00:17:51,300 --> 00:17:57,060 Well then what we want to do is we just want to clear out the scrolling frame and then return out of 256 00:17:57,060 --> 00:17:57,990 the function. 257 00:17:58,260 --> 00:18:03,690 So for example, if a person is typing in there and they're typing out something like colon, it's going 258 00:18:03,690 --> 00:18:05,880 to display all of the commands in our game. 259 00:18:05,880 --> 00:18:11,550 And then when they hit backspace we want to clear out the scrolling frame, meaning that the first text 260 00:18:11,550 --> 00:18:12,390 there is nothing. 261 00:18:12,390 --> 00:18:12,600 Right. 262 00:18:12,600 --> 00:18:16,560 So we want to clear out the scrolling frame and display nothing on their screen. 263 00:18:16,560 --> 00:18:20,430 Otherwise I'm going to create a variable called matching commands. 264 00:18:21,190 --> 00:18:25,390 And what we're going to do is we're going to loop through every single command in that variable we created, 265 00:18:25,390 --> 00:18:27,520 which was authorized commands. 266 00:18:28,240 --> 00:18:33,490 And we're going to do is first, if the search text. 267 00:18:35,210 --> 00:18:39,860 Uh, the first element is equal to just a colon. 268 00:18:39,860 --> 00:18:44,480 So let's say they only typed a colon into the text box. 269 00:18:44,840 --> 00:18:52,670 Then what we could do is we could just set matching commands equal to authorized commands, and then 270 00:18:52,670 --> 00:18:58,040 we'll just break out of this loop, because there's no need to loop through every other single function 271 00:18:58,040 --> 00:19:00,260 if the only thing they typed in is colon. 272 00:19:00,260 --> 00:19:05,090 And because they typed in colon, that means we're going to display to them all of the authorized commands 273 00:19:05,090 --> 00:19:06,410 they're able to use. 274 00:19:06,800 --> 00:19:12,560 Otherwise, if they typed more than a colon, then we're going to loop through every single usage and 275 00:19:12,560 --> 00:19:19,970 ipairs command dot usage, because we need to check if they're actually typing out the correct usage 276 00:19:19,970 --> 00:19:22,220 for this particular command if it matches or not. 277 00:19:22,220 --> 00:19:22,790 Right. 278 00:19:22,790 --> 00:19:28,610 So if admin settings dot prefix, concatenate it with this usage. 279 00:19:28,610 --> 00:19:31,280 And then we're going to get a substring of it. 280 00:19:31,920 --> 00:19:39,630 From the first index all the way to however much they typed inside of our text box. 281 00:19:39,630 --> 00:19:43,830 So the length of search text one. 282 00:19:43,830 --> 00:19:46,860 So search text one, you could use length. 283 00:19:46,860 --> 00:19:48,390 Or we could also do. 284 00:19:49,500 --> 00:19:50,490 Cohen, Len. 285 00:19:50,490 --> 00:19:51,930 Here for length. 286 00:19:52,140 --> 00:19:59,220 If it is not equal to search text one, then we're going to continue looping. 287 00:19:59,860 --> 00:20:05,230 So we're basically just in a substring of whatever this command's usage is. 288 00:20:05,230 --> 00:20:09,760 And if it's not equal to what we've typed out inside of our command line, then we're going to continue 289 00:20:09,760 --> 00:20:11,350 looping to the next usage. 290 00:20:11,350 --> 00:20:14,020 And if that doesn't match, we'll loop to the next usage. 291 00:20:14,020 --> 00:20:18,550 If that doesn't match, then we're going to loop to the next function and then check all those usages 292 00:20:18,550 --> 00:20:20,470 and so on and so forth. 293 00:20:21,010 --> 00:20:26,950 But if it does match, then we can insert this command inside of matching commands. 294 00:20:27,600 --> 00:20:32,850 And then we can go ahead and just break out of this loop and move on to the next command. 295 00:20:33,210 --> 00:20:38,700 And then once we're done doing all that, we can call our update scrolling frame function and pass the 296 00:20:38,700 --> 00:20:40,290 matching commands table. 297 00:20:40,290 --> 00:20:44,520 And then this function is going to go ahead and loop through all of those commands and create clones 298 00:20:44,520 --> 00:20:50,370 of those text labels and, you know, insert it into, uh, the scrolling frame. 299 00:20:50,700 --> 00:20:56,310 And actually, since this create command label is already creating a clone of our text label, we don't 300 00:20:56,310 --> 00:20:56,940 need to do it here. 301 00:20:56,940 --> 00:20:58,770 I'm not sure why I included that. 302 00:20:59,430 --> 00:21:03,900 Okay, so for the next function here, uh, what do we want to do when we want to display a message 303 00:21:03,900 --> 00:21:05,160 on the player's screen? 304 00:21:05,160 --> 00:21:06,540 Well, that's pretty simple. 305 00:21:06,540 --> 00:21:11,880 First we want to set the message frame dot position equal to the message frame invisible. 306 00:21:11,880 --> 00:21:14,340 So first we want to make it not visible on the screen. 307 00:21:14,490 --> 00:21:16,860 Then we want to set the text inside of it. 308 00:21:16,860 --> 00:21:21,750 So the message label dot text equal to the text passed to this function. 309 00:21:22,260 --> 00:21:26,370 And then we're going to use the tween service and create a new tween on our message frame. 310 00:21:26,870 --> 00:21:31,970 And we can make this tween last something like, uh, I don't know, 0.5 seconds and we can make it 311 00:21:31,970 --> 00:21:36,440 a little fancy by using a different enemies style like sign. 312 00:21:37,400 --> 00:21:43,520 And we want to set the position of this message frame equal to the message frame visible. 313 00:21:43,520 --> 00:21:47,090 And then we can call the play function on this tween. 314 00:21:47,540 --> 00:21:52,910 The next thing we want to do is what do we want to do when that button inside of our message frame gets 315 00:21:52,910 --> 00:21:53,420 clicked? 316 00:21:53,420 --> 00:21:55,670 Well, we want to hide the message frame. 317 00:21:55,670 --> 00:22:01,340 So we're going to use the tween service and create a new tween on our message frame. 318 00:22:02,210 --> 00:22:08,150 Again we can do tween info dot new 0.5 seconds and do enum dot easing style sign. 319 00:22:09,020 --> 00:22:14,150 And this time, instead of setting the position to be visible, we want to set the position to be not 320 00:22:14,150 --> 00:22:14,720 visible. 321 00:22:14,720 --> 00:22:18,740 So message frame invisible and then we just play this tween. 322 00:22:19,640 --> 00:22:20,210 All right. 323 00:22:20,210 --> 00:22:21,290 We're all good to go here. 324 00:22:21,290 --> 00:22:24,770 Let's go ahead and start filling out our event handlers. 325 00:22:25,160 --> 00:22:30,560 So the first thing we need to check here, when we lose focus in our input box, is whether or not the 326 00:22:30,560 --> 00:22:32,900 player pressed enter on their keyboard. 327 00:22:32,900 --> 00:22:38,150 So if they did not press enter, then we're just going to return because we don't care. 328 00:22:38,570 --> 00:22:43,580 If they did press enter, then what we need to do is we need to get the text that is inside of their 329 00:22:43,580 --> 00:22:44,210 input box. 330 00:22:44,210 --> 00:22:46,550 So input box, dot text. 331 00:22:46,760 --> 00:22:50,750 And then we can set the input box dot text to nothing. 332 00:22:51,260 --> 00:22:56,510 And then once that's done we're going to use our request event and invoke to the server to execute a 333 00:22:56,510 --> 00:22:57,050 command. 334 00:22:57,050 --> 00:22:59,630 So execute command. 335 00:23:00,410 --> 00:23:05,120 And that command is going to be whatever text they entered into that text box. 336 00:23:05,120 --> 00:23:11,000 And again, this is going to return back to us a boolean of whether or not we were successful, and 337 00:23:11,000 --> 00:23:15,020 then a message or an error message if we were not successful. 338 00:23:15,020 --> 00:23:20,480 So if we were not successful in executing this function, then we can display a message on the player's 339 00:23:20,480 --> 00:23:23,030 screen using that result variable. 340 00:23:23,660 --> 00:23:29,060 Otherwise, if we were successful in executing the command, then we can set the input box placeholder 341 00:23:29,060 --> 00:23:31,370 text equal to the success text. 342 00:23:32,590 --> 00:23:35,710 And then we can wait something like, I don't know, three seconds. 343 00:23:36,340 --> 00:23:44,950 And if the input box dot placeholder text is still equal to the success text, then we can set input 344 00:23:44,950 --> 00:23:49,450 box dot placeholder text equal to original text. 345 00:23:50,030 --> 00:23:55,760 Alrighty, now, the last function we need to fill out right here is for our Context Action Service. 346 00:23:55,760 --> 00:24:00,500 So we're binding this function to be our action for when we hit a semicolon on our keyboard. 347 00:24:00,500 --> 00:24:04,190 What do we want to do when a player hits a semicolon on their keyboard. 348 00:24:04,190 --> 00:24:10,190 Well, we want to tween our command line to be visible or invisible on the screen. 349 00:24:10,190 --> 00:24:16,550 So if our main frame dot position is equal to main frame visible. 350 00:24:16,550 --> 00:24:21,680 So if it's already visible on our screen and the player presses a semicolon, well, that means we want 351 00:24:21,680 --> 00:24:23,810 to make the frame no longer visible. 352 00:24:23,810 --> 00:24:27,800 So we can use the tween service to create a new tween on our main frame. 353 00:24:28,550 --> 00:24:31,070 Tween info dot new. 354 00:24:31,100 --> 00:24:36,230 We can do 0.5 seconds and we can do something fancy like enum dot easing style dot sign. 355 00:24:37,630 --> 00:24:42,220 And we want to set the position equal to the main frame invisible. 356 00:24:42,220 --> 00:24:44,140 And then we can just play this tween. 357 00:24:47,140 --> 00:24:54,490 Otherwise, if the main frame dot position is equal to main frame invisible, then that means we want 358 00:24:54,490 --> 00:24:56,920 to tween the main frame to be visible. 359 00:24:56,920 --> 00:25:06,550 So tween service create on our main frame tween info dot new point five enum using style sign and we 360 00:25:06,550 --> 00:25:09,850 want to tween the position to be visible. 361 00:25:10,270 --> 00:25:12,370 And then we can play this tween as well. 362 00:25:12,970 --> 00:25:13,930 And guess what? 363 00:25:13,930 --> 00:25:14,800 That's it. 364 00:25:14,800 --> 00:25:20,500 We are ready to go with our local script, and that means we should be able to test out whether or not 365 00:25:20,500 --> 00:25:22,210 our guy is working. 366 00:25:22,570 --> 00:25:28,870 And one little extra thing you can do down here is that, let's say in our guy, you forgot to set the 367 00:25:28,870 --> 00:25:32,470 main frame and the visible frame back to their hidden position. 368 00:25:32,470 --> 00:25:34,630 Let's say they were visible on our screen right now. 369 00:25:34,630 --> 00:25:39,340 Well, when the script runs, we can go ahead and make sure to set the main frame dot position equal 370 00:25:39,340 --> 00:25:44,170 to main frame invisible and do the same thing for the message frame. 371 00:25:47,170 --> 00:25:49,120 Uh, message frame invisible. 372 00:25:49,120 --> 00:25:49,870 There we go. 373 00:25:50,640 --> 00:25:56,340 Now we can go ahead and take our admin guy and place it back inside of admin assets, because again, 374 00:25:56,340 --> 00:25:59,310 our server script has to clone it from this folder. 375 00:26:01,170 --> 00:26:06,270 And since I did put inside of the settings module script my id. 376 00:26:06,270 --> 00:26:11,790 So since I put my ID in here, it's going to see that I am an admin and it should give me the guy on 377 00:26:11,790 --> 00:26:12,240 my end. 378 00:26:12,270 --> 00:26:15,480 So if we go and test and play out our game here. 379 00:26:16,530 --> 00:26:17,400 We get no errors. 380 00:26:17,400 --> 00:26:17,970 That's good. 381 00:26:17,970 --> 00:26:19,890 If I go ahead and hit semicolon. 382 00:26:19,890 --> 00:26:20,550 Look at that. 383 00:26:20,550 --> 00:26:22,140 We get our command line to show up. 384 00:26:22,290 --> 00:26:25,950 And then if I hit semicolon again, our command line disappears. 385 00:26:25,950 --> 00:26:28,050 Now let's say I have my chat open right now. 386 00:26:28,050 --> 00:26:30,660 If I hit semicolon look at that. 387 00:26:30,660 --> 00:26:36,900 Our command line does not move up because the game recognizes that the game engine is currently observing 388 00:26:36,900 --> 00:26:39,270 our input inside of the chat box. 389 00:26:39,270 --> 00:26:44,370 But once I get out of the chat box and then hit semicolon, our command line pops up. 390 00:26:44,730 --> 00:26:49,050 Now, the next thing we should test is when we press colon in here, it should show us all the commands 391 00:26:49,050 --> 00:26:49,650 we're able to use. 392 00:26:49,650 --> 00:26:50,790 So if I do colon. 393 00:26:51,580 --> 00:26:52,330 There we go. 394 00:26:52,330 --> 00:26:57,700 It's showing us currently that the only command we have is set speed and showing us it takes a player 395 00:26:57,700 --> 00:26:58,810 and a number. 396 00:26:59,200 --> 00:27:01,750 So let me actually go ahead and stop this test real quick. 397 00:27:01,750 --> 00:27:06,520 And I'm going to fill this up with a bunch of different random commands real quick. 398 00:27:06,520 --> 00:27:08,050 So I'll have example one. 399 00:27:08,050 --> 00:27:08,740 Example two. 400 00:27:08,740 --> 00:27:09,820 Example three. 401 00:27:10,470 --> 00:27:15,000 And for this usage we could do like set health. 402 00:27:15,000 --> 00:27:18,660 And for this one we could do something like fling. 403 00:27:18,660 --> 00:27:21,180 And then we'll get rid of the second parameter for this one. 404 00:27:21,180 --> 00:27:23,370 Again we're just doing this as an example. 405 00:27:23,370 --> 00:27:25,800 But if we go ahead and go back and test our game. 406 00:27:27,360 --> 00:27:30,600 When we go type out a colon in here, boom. 407 00:27:30,600 --> 00:27:32,010 It shows us we have three commands. 408 00:27:32,010 --> 00:27:37,950 We have access to set speed, which takes a player, and a number fling, which just takes a player, 409 00:27:37,950 --> 00:27:41,070 and then set health, which takes a player and a number. 410 00:27:41,070 --> 00:27:47,400 And if I continue typing, so if I type in set, it's going to get rid of fling, because fling is not 411 00:27:47,400 --> 00:27:49,080 matching our command. 412 00:27:49,350 --> 00:27:51,120 Uh, but it looks like it's being a little weird. 413 00:27:51,120 --> 00:27:55,890 But if we do, like, set this and then we do set speed, of course, it's only going to show us set 414 00:27:55,890 --> 00:27:56,580 speed. 415 00:27:56,580 --> 00:28:00,900 If we do set health, it's going to only show us set health and so on. 416 00:28:01,850 --> 00:28:04,970 But it appears it's still showing our fling function. 417 00:28:05,120 --> 00:28:11,780 And that's probably because if we go to our fling function here that we just made as an example, right. 418 00:28:11,780 --> 00:28:13,970 We also set it to have a usage of speed. 419 00:28:13,970 --> 00:28:17,720 So if I get rid of that and then we go back and test. 420 00:28:20,070 --> 00:28:20,490 Again. 421 00:28:20,490 --> 00:28:24,060 If I pull up my command line, put colon and then press S, there we go. 422 00:28:24,060 --> 00:28:26,220 We only get shown set speed, set health. 423 00:28:26,220 --> 00:28:31,470 And as I continue typing, it's only going to show us the commands that currently match this text that 424 00:28:31,470 --> 00:28:32,970 we've entered into our command line. 425 00:28:32,970 --> 00:28:35,340 So it continuously updates. 426 00:28:35,340 --> 00:28:40,230 And again, once we get rid of the colon, it clears out the command line and nothing else shows up 427 00:28:40,230 --> 00:28:40,920 in here. 428 00:28:41,220 --> 00:28:41,940 Okay. 429 00:28:41,940 --> 00:28:43,860 So we're finished scripting the client here. 430 00:28:43,860 --> 00:28:48,930 And in the next lecture we're going to continue testing our admin system by creating some commands. 431 00:28:48,930 --> 00:28:50,760 So I'll go ahead and see you there.